package cn.itcast.chapter04.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 朱新舜
 * @Date: 2020-05-31 19:59:53
 */
@WebServlet("/requestParamsServlet")
public class RequestParamsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println("用户名：" + name);
        System.out.println("密码：" + password);
        //获取参数名为"hobby"的值
        String[] hobbys = req.getParameterValues("hobby");
        System.out.print("爱好：");
        for (int i = 0; i < hobbys.length; i++) {
            System.out.print(hobbys[i] + ",");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
